#include<vector>
#include<iostream>
#include<bitset>
class Solution {
public:
    std::vector<int> res;
    int singleNumber(std::vector<int>& nums) {
        int n = nums.size();
        res.resize(32);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 32; j++) {
                res[j] += (((nums[i]) >> j) & 1);
            }
        }
        int ans = 0;
        for (int i = 0; i < 32; i++) {
            if (res[i] % 3 != 0) {
                ans |= 1 << i;
            }
        }
        return ans;
    }
};
